﻿@using EmployeeLeaveSystem.Shared;
@using EmployeeLeaveSystem.Shared.Models;
@inject IMessageService _MessageService;
@inject HttpClient _HttpClient;

@if (nowRules == null) {
    <Result Title="查询薪水规则失败">
        <Extra>有可能是因为尚未发布薪水规则，可以点击下方按钮来刷新</Extra>
    </Result>
} else {
    <h5>薪资规则：@nowRules.Name</h5>
    <div class="site-statistic-demo-card">
        <GridRow Gutter="(16,16)">
            <GridCol Xs="24" Sm="24" Md="9">
                <Card Style="width:100%">
                    <Statistic Title="基本工资CNY" Value="@nowRules.BaseSalary" Precision="2" ValueStyle="color: #3f8600;" Suffix="CNY">
                    </Statistic>
                </Card>
            </GridCol>
            <GridCol Xs="24" Sm="12" Md="7">
                <Card>
                    <Statistic Title="迟到一次扣款CNY" Value="@nowRules.CutSalaryComeLate" Precision="2" ValueStyle="color: #cf1322;" Suffix="CNY">
                    </Statistic>
                </Card>
            </GridCol>
            <GridCol Xs="24" Sm="12" Md="7">
                <Card>
                    <Statistic Title="加班补偿每小时CNY" Value="@nowRules.AddSalaryOverTime" Precision="2" ValueStyle="color: #3f8600;" Suffix="CNY">
                    </Statistic>
                </Card>
            </GridCol>
        </GridRow>
    </div>
    <GridRow>
        <GridCol Xs="24" Md="12">
            <div>发布时间：@nowRules.Created</div>
            <div>开始时间：@nowRules.StartTime</div>
        </GridCol>
        <GridCol Xs="24" Md="12">
            <div>发布人：@nowRules.Staff?.Name</div>
            <div>结束时间：@nowRules.EndTime</div>
        </GridCol>
    </GridRow>
}
<div>
    <Button OnClick="async ()=>{await OnParametersSetAsync();await InvokeAsync(StateHasChanged);}">刷新</Button>
</div>
<style>
    .site-statistic-demo-card {
        background: #ececec;
        padding: 30px;
    }
</style>

@code {
    /// <summary>
    /// 需要查询规则的部门ID
    /// </summary>
    [Parameter]
    public int? Id { get; set; }

    NowRules? nowRules = null;

    protected override async Task OnParametersSetAsync() {
        try {
            nowRules = await _HttpClient.GetFromJsonAsync<NowRules>($"/api/Salary/GetRulesByDepartmentId?id={Id}");
        }
        catch (Exception ex) {
            _MessageService.Error("获取规则失败失败 " + Id.ToString());
        }
    }
}
